<template>
  <a-modal
          title="爬虫任务基本信息配置"
          :width="640"
          :visible="visible"
          :confirmLoading="confirmLoading"
          @ok="handleSubmit"
          @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
                label="任务名称："
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
        >
          <a-input v-decorator="['desc', {rules: [{required: true, min: 5, message: '请输入至少五个字符的规则描述！'}]}]" />
        </a-form-item>
        <a-form-item
                label="任务描述："
                :labelCol="labelCol"
                :wrapperCol="wrapperCol1"
        >
          <a-input v-decorator="['desc', {rules: [{required: true, min: 5, message: '请输入至少五个字符的规则描述！'}]}]" />
        </a-form-item>
        <a-form-item
                label="数据库配置："
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
        >
          <a-textarea v-decorator="['desc',{rules: [{required: true, min: 5, message: '请输入至少五个字符的规则描述！'}]}]"></a-textarea>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 13 }
        },
        wrapperCol1: {
          xs: { span: 30 },
          sm: { span: 13 }
        },
        visible: false,
        confirmLoading: false,

        form: this.$form.createForm(this)
      }
    },
    methods: {
      add () {
        this.visible = true
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            console.log('values', values)
            setTimeout(() => {
              this.visible = false
              this.confirmLoading = false
              this.$emit('ok', values)
            }, 1500)
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.visible = false
      }
    }
  }
</script>
